#include <QtGui/QApplication>
#include <QDesktopWidget>
#include <QLabel>
#include <QTableWidget>
#include <QHeaderView>
#include <QNetworkInterface>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QWidget window;
    QTableWidget *tableWidget;

    tableWidget = new QTableWidget(&window);

    tableWidget->setEditTriggers(QAbstractItemView::DoubleClicked
                                | QAbstractItemView::SelectedClicked);
    tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
    tableWidget->setColumnCount(2);

    QStringList headerLabels;
    headerLabels << "Network Name" << "IP Address";
    tableWidget->setHorizontalHeaderLabels(headerLabels);
    tableWidget->verticalHeader()->hide();

    QList<QNetworkInterface> hosts = QNetworkInterface::allInterfaces();
    tableWidget->setRowCount(hosts.count());

    for (int i = 0, row = 0; i < hosts.count(); ++i) {
        //if (hosts[i].name().compare("eth0", Qt::CaseInsensitive))
        //    continue;
        QList<QNetworkAddressEntry> addrs = hosts[i].addressEntries();
        QTableWidgetItem *item0 = new QTableWidgetItem(hosts[i].name());
        tableWidget->setItem(row, 0, item0);
        if (!addrs.isEmpty()) {
            QTableWidgetItem *item1 = new QTableWidgetItem(addrs[0].ip().toString());
            tableWidget->setItem(row, 1, item1);
        }

        tableWidget->setRowHeight(row, 100);
        ++row;
    }

    //tableWidget->resizeColumnsToContents();

    tableWidget->setColumnWidth(0, QApplication::desktop()->width()/2);
    tableWidget->setColumnWidth(1, QApplication::desktop()->width()/2);
    tableWidget->resize(QApplication::desktop()->width(), QApplication::desktop()->height());

    window.showMaximized();

    return app.exec();
}

